<style scoped>
    .layui-form >>> .layui-form-select{
        z-index: inherit;
    }
</style>

<template>
    <div class="company">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>添加数据项</legend>
        </fieldset>

        <form class="layui-form " >
            <div class="layui-form-item">
                <label class="layui-form-label">抽检项名称</label>
                <div class="layui-input-block">
                    <input type="text" name="itemname" :value="qaitems.itemname" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">最大可接受比率</label>
                <div class="layui-input-block">
                    <input type="text" name="maxacctval" :value="qaitems.maxacctval"   placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label class="layui-form-label" >分级标准</label>
                <div class="layui-input-block" >
                    <input type="hidden" name="qastandardname" ref="qastandardname" />
                    <select name="qastandard" lay-verify="required" lay-filter="qastandard">
                        <option value="">请选择</option>
                        <option v-for="(item, index) in standards" :value="item.guid">{{item.standard}}</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" >
                <label class="layui-form-label" >质检标准</label>
                <div class="layui-input-block" >
                    <select   id="qaMainGuid"  name="qamainguid"  lay-filter="qaMainGuid" lay-verify="required"     lay-search="">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>





            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input type="text" name="listorder" :value="qaitems.listorder" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label">状态 {{qaitems.status}}</label>-->
<!--                <div class="layui-input-block">-->

<!--                    <select   id="status"  name="status"  lay-filter="status" required  v-model="qaitems.status"   lay-search="">-->
<!--                        <option value="1"   >启用</option>-->
<!--                        <option value="0">禁用</option>-->
<!--                    </select>-->

<!--                </div>-->
<!--            </div>-->


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                    <button class="layui-btn layui-btn-primary" @click="$parent.back">返回</button>
                </div>
            </div>
            <div style="height: 500px"></div>
        </form>
    </div>
</template>

<script>
    export default {
        name: 'QaitemsAdd',
        props: ['id'],
        data () {
            return {
                guid : this.id,
                adata: {},
                qaitems:{},
                typeEmnu:[],
                costincomeEmnu:[],
                standards: '',
                standard: ''
            }
        },
        mounted() {
            let that = this;
            layui.use(['form'], function () {
                var form = layui.form,
                    layer = layui.layer;

                let loader = layer.load();


                $.ajax({
                    url: '/trace/Qamain!get.action',
                    data: {},
                    type: "post",
                    dataType: "json",
                    success: function(res) {
                        if (res.info != "error") {


                            $.each(res, function (index, item) {

                                    $('#qaMainGuid').append("<option   value="  +item.guid +  " >" + item.qaname    + "</option>" );

                            });

                            form.render('select');
                        } else {
                            that.toast("系统错误");
                        }
                    },
                    complete: function () {
                        layer.close(loader);
                    }
                });


                form.on('select(qastandard)', function (data) {
                    let standard = that.standards.filter(item => {
                        return item.guid == data.value;
                    })[0];
                    that.$refs.qastandardname.value = standard.standard;
                });

                //提交编辑过的数据
                form.on('submit(submit)', function (data) {
                    let loader = layer.load();
                    $.ajax({
                        url: '/harvest/Qaitems!insert.action',
                        data: data.field,
                        type: "post",
                        dataType: "json",
                        success: function(res) {
                            if (res.info == "success") {
                                that.toast("添加成功");
                                that.$parent.switchPage('Qaitems');
                            }  else{
                                that.toast("系统错误");
                            }
                        },
                        complete: function () {
                            layer.close(loader);
                        }
                    });
                    return false;
                });
            });
            this.getStandards();
        },
        updated() {
            layui.form.render();
        },
        methods: {
            getStandards: function () {
                let that = this;
                this.axios({
                    method: 'get',
                    responseType: 'json',
                    url: '/harvest/Qastandard!getQastandards.action',
                }).then(response => {
                    if (response.data.msg == "success") {
                        that.standards = response.data.standards;
                    } else {
                        this.toastText('获取扣杂标准数据失败');
                    }
                });
            },
            back: function () {
                this.$parent.switchPage(this.$parent.refView);
            },
            getqamain: function (){

            }

        }
    }
</script>
